package alibaba.server;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Snapshots {
    
    private Map<Integer, Set<ListingEntry>> snapshotEntries;
    
    public Snapshots(String userName) {
    	snapshotEntries = new HashMap<Integer, Set<ListingEntry>>();
    }
    
    public boolean containsSnapshot(int snapshotNumber) {
        return snapshotEntries.containsKey(snapshotNumber);
    }
    
    public void removeSnapshot(int snapshotNumber) {
       snapshotEntries.remove(snapshotNumber);
    }
    
    public void addSnapshotEntry(int snapshotNumber, ListingEntry listingEntry) {
    	Set<ListingEntry> listingEntrySet;
    	if (!snapshotEntries.containsKey(snapshotNumber)) {
    		listingEntrySet = new HashSet<ListingEntry>();
    		snapshotEntries.put(snapshotNumber, listingEntrySet);
    	} else {
    		listingEntrySet = snapshotEntries.get(snapshotNumber);
    	}
    	listingEntrySet.add(listingEntry);
    }
    
    public Set<ListingEntry> getCurrentSnapshot() {
        return getSnapshotEntries(0);
    }
    
    public Set<ListingEntry> getSnapshotEntries(int snapshotNumber) {
        return snapshotEntries.get(snapshotNumber);
    }
    
    public Set<Integer> getAvailableSnapshots() {
    	return snapshotEntries.keySet();
    }
    
        
}